﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Zwms.Data.BusinessObjects;

namespace Zwms.Client.ManageWms
{
    public partial class StockOpenBoxForm : Form
    {
        private StoGoodsStock _updateRecord;
        public StockOpenBoxForm(StoGoodsStock record)
        {
            InitializeComponent();
            SetValueToUI(record);
        }

        private void SetValueToUI(StoGoodsStock record)
        {
            this.tbStockCode.Text = record.Id;
            this.nudPkgQty.Value = record.PackageQty;
            this.nudPieceQty.Value = record.PieceQty;
            this.nudSpec.Value = record.GoodsSpec;
            this.nudOpenQty.Value = 0;
            this.nudOpenQty.Maximum = record.PackageQty;
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                if (this.nudOpenQty.Value > this.nudPkgQty.Value)
                {
                    MessageBox.Show("拆箱数目不能大于库存箱数，请检查！");
                    return;
                }
                ServiceReferenceZwms.ServiceZwmsClient client = new ServiceReferenceZwms.ServiceZwmsClient();
                StoGoodsStock record = new StoGoodsStock();
                record.Id = this.tbStockCode.Text.Trim();
                this._updateRecord = client.QueryGoodsStock(record);
                this._updateRecord.PackageQty = (int)(this.nudPkgQty.Value-this.nudOpenQty.Value);
                this._updateRecord.PieceQty = (int)(this.nudPieceQty.Value+this.nudOpenQty.Value*this.nudSpec.Value);
                client.UpdateGoodsStock(this._updateRecord);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Cursor = Cursors.Default;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }
    }
}
